﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;

namespace HIWSystem.Attributes
{
    /// <summary>
    /// 自定义正则表达式验证特性类
    /// </summary>
    public class RegularExpressionAttribute : BaseValidateAttribute
    {
        public RegularExpressionAttribute(string description,string pattern)
        {
            _description = description;
            _pattern = pattern;
        }
        private string _description;
        /// <summary>
        ///  /// <summary>
        /// 验证不通过的提示信息
        /// </summary>
        /// </summary>
        public override string Description
        {
            get { return _description; }
            set { _description = value; }
        }
        private string _pattern;
        /// <summary>
        /// 验证模式
        /// </summary>
        public string Pattern
        {
            get { return _pattern; }
            set { _pattern = value; }
        }
        /// <summary>
        /// 验证
        /// </summary>
        /// <param name="value">值</param>
        /// <returns></returns>
        public override bool Validate(object value)
        {
            return new Regex(Pattern).IsMatch(value.ToString());
        }
    }
}
